/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package campeonatobrasuka.TableModels;

import Persistencia.DAO;
import Persistencia.daos.TimeDAO;
import Persistencia.modelos.Time;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author HP
 */
public class ClubeTableModel extends AbstractTableModel {

    private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    private DAO<Integer, Time> dao = new TimeDAO();
    private List<Time> lista = (List<Time>) dao.recuperaTodos();

    public int getRowCount() {
        return lista.size();
    }
    
    public Object getObjectAt(int rowNum){
          return lista.get(rowNum);
    }   

    
    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Time Time = lista.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return Time.getNomeTime();
            default:
                return (Time.getTecnico()==null)?"nenhum":Time.getTecnico().getNomePessoa();
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Nome do Time";
            default:
                return "Nome do Técnico";           
        }
    }

    public void atualizar() {
        lista = (List<Time>) dao.recuperaTodos();
        fireTableDataChanged();
    }
}
